package com.tudouji.project.produce.controller;

import java.util.List;

import com.tudouji.project.produce.domain.Pickinglist;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.tudouji.framework.aspectj.lang.annotation.Log;
import com.tudouji.framework.aspectj.lang.enums.BusinessType;
import com.tudouji.project.produce.domain.Materialretapply;
import com.tudouji.project.produce.service.IMaterialretapplyService;
import com.tudouji.framework.web.controller.BaseController;
import com.tudouji.framework.web.domain.AjaxResult;
import com.tudouji.common.utils.poi.ExcelUtil;
import com.tudouji.framework.web.page.TableDataInfo;

/**
 * 退料Controller
 * 
 * @author tudouji
 * @date 2022-06-01
 */
@RestController
@RequestMapping("/produce/materialretapply")
public class MaterialretapplyController extends BaseController
{
    @Autowired
    private IMaterialretapplyService materialretapplyService;

    /**
     * 查询报废列表
     */
    @GetMapping("/wxList")
    public TableDataInfo wxList(Materialretapply materialretapply,String status,String functionType)
    {
        startPage();
        List<Materialretapply> list = materialretapplyService.selectMaterialretapplyList(materialretapply, status, functionType);
        return getDataTable(list);
    }

    /**
     * 查询报废列表
     */
    @PreAuthorize("@ss.hasPermi('produce:materialretapply:list')")
    @GetMapping("/list")
    public TableDataInfo list(Materialretapply materialretapply)
    {
        startPage();
        List<Materialretapply> list = materialretapplyService.selectMaterialretapplyList(materialretapply);
        return getDataTable(list);
    }

    /**
     * 导出报废列表
     */
    @PreAuthorize("@ss.hasPermi('produce:materialretapply:export')")
    @Log(title = "退料", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Materialretapply materialretapply)
    {
        List<Materialretapply> list = materialretapplyService.selectMaterialretapplyList(materialretapply);
        ExcelUtil<Materialretapply> util = new ExcelUtil<Materialretapply>(Materialretapply.class);
        return util.exportExcel(list, "materialretapply");
    }

    /**
     * 获取报废详细信息
     */
    @GetMapping(value = "/{guid}")
    public AjaxResult getInfo(@PathVariable("guid") Long guid)
    {
        return AjaxResult.success(materialretapplyService.selectMaterialretapplyByNewId(guid));
    }

    /**
     * 新增报废
     */
    @PreAuthorize("@ss.hasPermi('produce:materialretapply:add')")
    @Log(title = "退料", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Materialretapply materialretapply)
    {
        return toAjax(materialretapplyService.insertMaterialretapply(materialretapply));
    }

    /**
     * 修改报废
     */
    @PreAuthorize("@ss.hasPermi('produce:materialretapply:edit')")
    @Log(title = "退料", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Materialretapply materialretapply)
    {
        return toAjax(materialretapplyService.updateMaterialretapply(materialretapply));
    }

    /**
     * 删除报废
     */
    @PreAuthorize("@ss.hasPermi('produce:materialretapply:remove')")
    @Log(title = "退料", businessType = BusinessType.DELETE)
	@DeleteMapping("/{guids}")
    public AjaxResult remove(@PathVariable String[] guids)
    {
        return toAjax(materialretapplyService.deleteMaterialretapplyByIds(guids));
    }


    /**
     * 发起
     */
    @Log(title = "发起", businessType = BusinessType.INSERT)
    @PostMapping("/save")
    public AjaxResult save(@RequestBody Materialretapply materialretapply, String fileIds)
    {
        return materialretapplyService.save(materialretapply, fileIds);
    }

    @Log(title = "审批", businessType = BusinessType.OTHER)
    @PostMapping("/approval")
    public AjaxResult approval(Long taskid,Long id,String opinion,@RequestParam(value="fileIds",required = false)String imgids){
        return materialretapplyService.approval(id, imgids, opinion, taskid);
    }

    @Log(title = "入库", businessType = BusinessType.OTHER)
    @PostMapping("/inStoreroom")
    public AjaxResult inStoreroom(Long taskid, Long id, @RequestBody Materialretapply materialretapply, String opinion
            , @RequestParam(value="fileIds",required = false)String imgids){
        materialretapply.setId(id);
        return materialretapplyService.inStoreroom(materialretapply, imgids, opinion, taskid);
    }

    @Log(title = "拒绝", businessType = BusinessType.OTHER)
    @PostMapping("/refuse")
    public AjaxResult refuse(Long taskid,Long id,String opinion,String fileIds,Long refuseNodeid,Long backUserid){
        return materialretapplyService.refuse(id, fileIds, opinion, taskid,refuseNodeid,backUserid);
    }

    /**
       删除
     */
    @Log(title = "删除", businessType = BusinessType.DELETE)
    @PostMapping("/del")
    public AjaxResult del(Long id) {
        return materialretapplyService.del(id);
    }
}
